package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.DishDto;
import com.itheima.reggie.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired
    private DishService dishService;

    //添加菜品和菜品口味
    @PostMapping
    public R add(@RequestBody DishDto dishDto){
        R r = dishService.add(dishDto);
        return r;
    }
    //菜品分页查询
    @GetMapping("/page")
    public R findPage(Integer page,Integer pageSize,String name){
        R r = dishService.findPage(page,pageSize,name);
        return r;
    }
    //根据ID查询菜品信息和菜品口味
    @GetMapping("/{id}")
    public R findById(@PathVariable Long id){
        R r = dishService.findById(id);
        return r;
    }
    //修改
    @PutMapping()
    public R update(@RequestBody DishDto dishDto){
        return dishService.update(dishDto);
    }
    //批量删除
    @DeleteMapping()
    public R deleteIds(Long[] ids){
        R r  = dishService.deleteIds(ids);
        return r;
    }
    //批量起售
    //批量停售
    @PostMapping("/status/{id}")
    public R modyfiStatus(Long[] ids,@PathVariable Integer id){
        R r = dishService.modyfiStatus(ids,id);
        return r;
    }
    //根据分类id查询出菜品的集合信息
    @GetMapping("/list")
    public R findList(Long categoryId){
        R r  = dishService.findList(categoryId);
        return r;
    }
}
